package org.bigjava.user.web.controller;

import org.bigjava.bean.Posts;
import org.bigjava.bean.Topic;
import org.bigjava.user.mapper.UserFunctionMapper;
import org.bigjava.user.service.impl.UserFunctionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/others/")
public class OthersController {
    @Autowired
    UserFunctionServiceImpl userFunctionService;

    @RequestMapping("queryothersCollect")
    public ModelAndView queryothersCollect(HttpSession session){

        //查询用户收藏的全部话题  ok
        System.out.println("他的收藏");
        String id = (String)session.getAttribute("othersid");
        List<Posts> posts = userFunctionService.queryUserCollect(id);
        System.out.println(posts);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("posts",posts);
        modelAndView.addObject("id",id);
        modelAndView.setViewName("Otherscollect");

        return modelAndView;
    }

    @RequestMapping("queryOthersposts")
    public ModelAndView queryOthersposts(HttpSession session){
        System.out.println("他的帖子");
        String id = (String)session.getAttribute("othersid");
        ModelAndView modelAndView = new ModelAndView();
        List<Posts> posts = userFunctionService.querymyposts(id);
        System.out.println(posts);
        modelAndView.addObject("posts",posts);
        modelAndView.setViewName("Othersposts");

        return modelAndView;
    }

    @RequestMapping("queryOtherscommment")
    public ModelAndView queryOtherscomment(HttpSession session){
        System.out.println("他的评论");
        String id = (String)session.getAttribute("othersid");
        ModelAndView modelAndView = new ModelAndView();
        List  comments=userFunctionService.querymycomment(id);
        System.out.println(comments);
//        List<Reply> replies = userFunctionService.queryReply(id);
        modelAndView.addObject("comment",comments);
//        modelAndView.addObject("reply",replies);
        modelAndView.setViewName("Otherscomment");
        return modelAndView;
    }

    @RequestMapping("queryAttentionOthers")
    public ModelAndView queryAttentionOthers(HttpSession session){
        //查询用户关注的全部话题
        ModelAndView modelAndView = new ModelAndView();
        String id = (String)session.getAttribute("othersid");
        System.out.println("查询他的全部关注"+id);
        List<Topic> topics = userFunctionService.queryAttentiontopicName(id);

        for(Topic t:topics)System.out.println(t);
        modelAndView.addObject("topics",topics);
        modelAndView.addObject("userid",id);
        modelAndView.setViewName("Othersattention");


        return modelAndView;
    }

}
